/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pokergame;

import java.io.Serializable;

/**
 *
 * @author erik
 */
public class Player implements Serializable{
    private Hand currentHand;
    private int kitty;
    private String userName;
    
    
    public Player(String userName,int initalKitty) throws Exception{
        if(!isValidUserName(userName)){
            throw new Exception("Failed, username not valid");
        }
        this.userName=userName;
        kitty=initalKitty;
    }
    /**
     * Check to see if the username is valid
     * @param in
     * @return 
     */
    public static boolean isValidUserName(String in){
        //only alphnumber and spaces
        for(int i=0;i<in.length();i++){
            if(!(Character.isAlphabetic(in.charAt(i)) || 
                    Character.isDigit(in.charAt(i)) ||
                    in.charAt(i)==' '))
                return false;
        
        }
        return true;
    }
    
    public int getKitty(){
        return kitty;
    }
    /**
     * @param fundsToRemove
     * @return false if more money was attempted to be removed than was present in the kitty
     */
    public boolean removeFunds(int fundsToRemove){
        if(fundsToRemove>this.kitty){
            return false;
        }
        this.kitty-=fundsToRemove;
        return true;
    }
    /**
     * Will add the winnings to the players kitty
     * @param fundsToAdd
     * @return 
     */
    public void recieveWinnings(int fundsToAdd){
        this.kitty+=fundsToAdd;
    }
    /**
     * Pass in a hand to the player object
     * @param handDelt 
     */
    public void receiveHand(Hand handDelt){
        this.currentHand=handDelt;
    }
    /**
     * get the hand the  player has
     * @return 
     */
    public Hand getCurrentHand(){
        return this.currentHand;
    }
    
    public String getUserName(){
        return this.userName;
    }
}
